/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package astroLib;
/**
 *
 * @author mehmetrg
 */
public class SalatTimes {
    private TimeForSunAngle fajr,sunRise,asrH,asrS,magrib,isha;
    double rad=Math.PI/180;
    double zuhr;
    private double MJD0h, longitude, latitude;
       //private double[] temkin={-3,-6,7,4,4,8,1}; istatistiki super  bunlar
    private  double sinAltitude,altitude,cotAltitude, asrShafiAngle,asrHanafiAngle;
/*    public SalatTimes ()
    {
        this(Math.toRadians(39.95),Math.toRadians(32.85),2.0,2008,3,20);
    }*/
     public SalatTimes (EarthPosition earth,double timeZone,int year,int month,int day)
    {
        this(earth,(APC_Time.Mjd(year,month,day,0,0,0) - timeZone/24));

    }
    public SalatTimes ( double latitude,double longitude, double timeZone,int year,int month,int day)
    {
       this(new EarthPosition(latitude,longitude),(APC_Time.Mjd(year,month,day,0,0,0) - timeZone/24));
    }

    public SalatTimes (EarthPosition earth,  double MJD0h)
    {
        this.latitude=earth.getLatitude();
        this.longitude=earth.getLongitude();

        //MJD0h=APC_Time.Mjd(year,month,day,0,0,0) - timeZone/24;
        this.MJD0h=MJD0h;

        sunRise= new TimeForSunAngle (-50.0/60.0, MJD0h, longitude, latitude);// Sunrise               at h=-50'

        sinAltitude=sunRise.getSinAltitudeForMidday();
        altitude=MATH.asin(sinAltitude);	/* Radians	*/

        cotAltitude= 1.0 / Math.tan(altitude);
        asrShafiAngle	= Math.toDegrees(Math.PI/2 - MATH.atan2((1.0 + cotAltitude), 1.0));

        asrHanafiAngle= Math.toDegrees(Math.PI/2 - MATH.atan2((2.0 + cotAltitude), 1.0));
      //  System.out.println( " Math.toDegrees(altitude)"+ Math.toDegrees(altitude));
    }

     public double getFajrTime (double twilightAngle, int temkin)
        {    fajr= new TimeForSunAngle (twilightAngle, MJD0h, longitude, latitude);
              //System.out.println(APC_Time.Time(fajr.getRiseTime()+temkin/60));
              return fajr.getRiseTime()+temkin/60.0;
        }
      public double getSunRiseTime (double sunRiseAngle, int temkin)
        {   sunRise= new TimeForSunAngle (sunRiseAngle, MJD0h, longitude, latitude);// Sunrise

            //System.out.println(APC_Time.Time(sunRise.getRiseTime()+temkin/60.0));
            
            double MJD=MJD0h+sunRise.getRiseTime()/24.0;
            double T   = (MJD-51544.5)/36525.0;
           // System.out.println("SunRise Angle: "+APC_Sun.MiniSun(T).Equ2Hor(latitude,longitude,MJD).getElevation());

            return sunRise.getRiseTime()+temkin/60.0;
        }
      public double getZuhrTime (int temkin)
        {   zuhr=(sunRise.getRiseTime()+sunRise.getSetTime())/2;
             //System.out.println(APC_Time.Time(zuhr+temkin/60.0));

            return zuhr+temkin/60.0;
        }
    /*
     * To compute Asr, first compute the altitude at noon,
     * Al at noon (altitudeNoon) is 90? - zenith angle.
     * Now, asrShafi is 90? - arccot(1 + cot(altitudeNoon))
     * and asrHanafi is 90? - arccot(2 + cot(altitudeNoon))
     * Then, compute the setting times at these angles.
     */
      public double getAsrSafiTime (int temkin)
        {
            asrS=new TimeForSunAngle (asrShafiAngle, MJD0h, longitude, latitude)  ;
            //System.out.println(APC_Time.Time(asrS.getSetTime()+temkin/60.0));
            return asrS.getSetTime()+temkin/60.0;
        }
      public double getAsrHanefiTime (int temkin)
        {
            asrH=new TimeForSunAngle (asrHanafiAngle, MJD0h, longitude, latitude)  ;
             //System.out.println(APC_Time.Time(asrH.getSetTime()+temkin/60.0));
            return asrH.getSetTime()+temkin/60.0;
        }
       public double getMagribTime (double sunSetAngle, int temkin)
        {
           magrib= new TimeForSunAngle (sunSetAngle, MJD0h, longitude, latitude);
              double MJD=MJD0h+sunRise.getSetTime()/24.0;
            double T   = (MJD-51544.5)/36525.0;
            //System.out.println("Sunset"+APC_Sun.MiniSun(T).Equ2Hor(latitude,longitude,MJD).getElevation());
           //System.out.println(APC_Time.Time(magrib.getSetTime()+temkin/60.0));
           return magrib.getSetTime()+temkin/60.0;
        }
      public double getIshaTime (double twilightAngle, int temkin)
        {
            isha= new TimeForSunAngle (twilightAngle, MJD0h, longitude, latitude);
            //System.out.println(APC_Time.Time(isha.getSetTime()+temkin/60.0));
            return isha.getSetTime()+temkin/60.0;
        }
         public double getIsrakTime (double twilightAngle, int temkin)
        {
            isha= new TimeForSunAngle (twilightAngle, MJD0h, longitude, latitude);
            //System.out.println(APC_Time.Time(isha.getSetTime()+temkin/60.0));
            return isha.getSetTime()+temkin/60.0;
        }
            public double getIstivaTime (double twilightAngle, int temkin)
        {
            isha= new TimeForSunAngle (twilightAngle, MJD0h, longitude, latitude);
            //System.out.println(APC_Time.Time(isha.getSetTime()+temkin/60.0));
            return isha.getSetTime()+temkin/60.0;
        }
            public double getIsfirarTime (double twilightAngle, int temkin)
        {
            isha= new TimeForSunAngle (twilightAngle, MJD0h, longitude, latitude);
            //System.out.println(APC_Time.Time(isha.getSetTime()+temkin/60.0));
            return isha.getSetTime()+temkin/60.0;
        }


  
 }

